package com.example.drive.student.controller;


import com.example.drive.common.R;
import com.example.drive.student.pojo.dto.UpdateStuDTO;
import com.example.drive.student.pojo.entity.Student;
import com.example.drive.student.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("student")
public class StudentController {
     @Autowired
    private StudentService studentService;

     /**
      * 获取学员
      */
    @GetMapping("list")
    public R<List<Student>> getStudentList(){
        List<Student> studentList= studentService.getList();
        return R.ok(studentList);
    }

    /**
     * 修改学员信息
     * @param updateStuDTO
     * @return
     */
    @PutMapping("update/{id}")
    public R<Void> updateCoach(@PathVariable Integer id,@RequestBody @Validated UpdateStuDTO updateStuDTO){
      studentService.update(id,updateStuDTO);
      return R.ok();
    }

    /**
     * 查询学员
     * @param id
     * @return
     */
    @GetMapping("search/{id}")
    public R<Student> searchStudent(@PathVariable Integer id){
       Student student= studentService.search(id);
       return R.ok(student);
    }

    /**
     * 更新分数
     * @param id
     * @param subject
     * @param newScore
     * @return
     */
    @PutMapping("updateScore/{id}/{subject}")
    public R<Void> updateScore(@PathVariable Integer id, @PathVariable String subject, @RequestParam Integer newScore) {
        System.out.println(newScore);
        studentService.updateScore(id, subject, newScore);
        return R.ok();
    }

    /**
     * 决绝分配教练
     * @param id
     * @return
     */
    @PostMapping("refuse/{id}")
    public R<Void> refuseCoach(@PathVariable Integer id){
        studentService.refuse(id);
        return R.ok();
    }
}
